<?php

namespace app\common\model;

use think\Model;
use think\Db;

class Member extends Model {
	function getlist($map, $sort = 'user_id desc') {
		$pre = config ( 'database.prefix' );
		return db ( 'member m' )->leftJoin ( "{$pre}member_role r", "r.id=m.role_id" )->where ( $map )->order ( $sort )->field ( "m.*,r.title as role_name" )->paginate ( 10 );
	}
	function getInfo($map = '') {
		$pre = config ( 'database.prefix' );
		return db ( 'member m' )->leftJoin ( "{$pre}member_role r", "r.id=m.role_id" )->where ( $map )->field ( 'm.*,r.title as role_name' )->find ();
	}
	function add($data) {
		return db ( 'member' )->insertGetId ( $data );
	}
	function edit($map, $data) {
		return db ( 'member' )->where ( $map )->update ( $data );
	}
	function incMoney($map, $money = 1) {
		return db ( 'member' )->where ( $map )->setInc ( 'money', $money );
	}
	function incLockMoney($map, $money) {
		return db ( 'member' )->where ( $map )->setInc ( 'lock_money', $money );
	}
	function decMoney($map, $money = 1) {
		return db ( 'member' )->where ( $map )->setDec ( 'money', $money );
	}
	function decLockMoney($map, $money) {
		return db ( 'member' )->where ( $map )->setDec ( 'lock_money', $money );
	}
	function getAllRole($map = '') {
		return db ( 'member_role' )->where ( $map )->order ( 'sort_id asc' )->select ();
	}
	function addRole($data) {
		return db ( 'member_role' )->insertGetId ( $data );
	}
	function editRole($map, $data) {
		return db ( 'member_role' )->where ( $map )->update ( $data );
	}
	function delRole($map) {
		return db ( 'member_role' )->where ( $map )->delete ();
	}
		function del($map) {
		return db ( 'member' )->where ( $map )->delete ();
	}
	function roleInfo($map) {
		return db ( 'member_role' )->where ( $map )->find ();
	}
	function addMoneyLog($data) {
		return db ( 'money_log' )->insertGetId ( $data );
	}
	function getUpgrade($map) {
		return db ( 'member_upgrade u' )->leftJoin ( "member m", "m.user_id=u.user_id" )->leftJoin ( "member_role r", "r.id=u.role_id" )->where ( $map )->field ( "u.*,r.title as role_name,r.deposit as money" )->select ();
	}
	function addUpgrade($data) {
		return db ( 'member_upgrade' )->insertGetId ( $data );
	}
}

?>